<?

require_once("cls_db.php");

class cls_customer
{
	function insert_customer($arr)
	{
		$db 	= new db();
		$sql	= "INSERT INTO tbl_customer (firstname, lastname, email, date, remark, user_session)".
					"VALUES ('{$arr['firstname']}',".
					"'{$arr['lastname']}',".
					"'{$arr['email']}',".
					"'{$arr['date']}',".
					"'{$arr['remark']}',".
					 "'".session_id()."')";
					
				
		if ($db->execute_nonquery($sql))
		{
			$id		= $db->get_insert_id();
			
			//echo $id;
									
			$sql	= "UPDATE tbl_salesinfo SET ".
						"customer_id =".$id.
						" WHERE user_id = '".session_id()."'".
						" AND customer_id =0";
						//echo $sql;
						
			$db->execute_nonquery($sql);
			return $id;
				
		}
		
	}//insert_reserve
	function get_customer($pageno = 1)
	{
		$db 	= new db();
		
		$sql	= "SELECT * FROM tbl_customer c, tbl_salesinfo s ".
					"WHERE c.customer_id = s.customer_id ORDER BY s.id";
		
		//$sql	= "SELECT * FROM tbl_customer";
		
		$db->set_pageno($pageno);
		$result = $db->get_datalist($sql);

		$result['pagecount']	= $db->get_pagecount();
		$result['numrows']		= $db->get_numrows($sql);
		
		$db->db_close();
		
		return $result;

		//$row = $db->get_all_data($sql);

		//if (count($row)) {
			//return $row;
		//}
	}//get_user
	function get_date_customer($pagen,$fromdate,$todate)
	{	
		$db 	= new db();
		
		$sql	="SELECT * FROM tbl_customer c , tbl_salesinfo s WHERE c.customer_id = s.customer_id AND c.date >= '$fromdate' ".
				"AND c.date <= '$todate' ";			
	
//	echo $sql;
		//$sql	= "SELECT * FROM tbl_customer";
		
		$db->set_pageno($pageno);
		$result = $db->get_datalist($sql);

		$result['pagecount']	= $db->get_pagecount();
		$result['numrows']		= $db->get_numrows($sql);
		
		$db->db_close();
		
		return $result;
		
		//$result	= $db->get_all_data($sql);
		
		//$db->db_close();
		
		//return $result;
		//$row = $db->get_all_data($sql);

		//if (count($row)) {
			//return $row;
		//}
	}
	
	function get_coordinator_saleslist($coordinator_id,$pageno= 1)
	{	
		$db 	= new db();
		
		$sql	="SELECT * FROM tbl_customer c, tbl_salesinfo s ".
					"WHERE c.customer_id =s.customer_id and s.coordinator_id=".$coordinator_id;
	
		
		//$sql	= "SELECT * FROM tbl_customer";
		
		$db->set_pageno($pageno);
		$result = $db->get_datalist($sql);

		$result['pagecount']	= $db->get_pagecount();
		$result['numrows']		= $db->get_numrows($sql);
		
		$db->db_close();
		
		return $result;
		
		//$result	= $db->get_all_data($sql);
		
		//$db->db_close();
		
		//return $result;
		//$row = $db->get_all_data($sql);

		//if (count($row)) {
			//return $row;
		//}
	}//get_user
	
	function get_coordinator_saleslist1($pageno= 1,$fromdate,$todate,$coordinator_id)
	{	
		$db 	= new db();
		
		$sql	="SELECT * FROM tbl_customer c , tbl_salesinfo s WHERE c.customer_id = s.customer_id AND c.date >= '$fromdate' ".
				"AND c.date <= '$todate' "."and s.coordinator_id=".$coordinator_id;				
	
//	echo $sql;
		//$sql	= "SELECT * FROM tbl_customer";
		
		$db->set_pageno($pageno);
		$result = $db->get_datalist($sql);

		$result['pagecount']	= $db->get_pagecount();
		$result['numrows']		= $db->get_numrows($sql);
		
		$db->db_close();
		
		return $result;
		
		//$result	= $db->get_all_data($sql);
		
		//$db->db_close();
		
		//return $result;
		//$row = $db->get_all_data($sql);

		//if (count($row)) {
			//return $row;
		//}
	}//get_user
	
	function get_pdf($cut)
	{
		$db 	= new db();
		$sql	= "SELECT * FROM tbl_customer WHERE customer_id = ".$cut;

		$result	= $db->get_all_data($sql);
		
		$db->db_close();
		
		return $result;
	}//get_tour_detail
}//class
?>